<?php




/**
 * 用户列表
 *
 */
function li($page_size = ADM_PAGESIZE) {
    global $_TABLES, $class_var, $timestamp;

    $view_var   = array();
    $tbl_faq    = "yu_sqjm";
    $conn   = & get_db_conn();


    $where      = 'WHERE 1 ';
    // 关键字
    $key    = trim(@$_GET['key']);
    if($key != '') $where  .= "AND (cmname LIKE '%$key%' OR realname LIKE '%$key%' )";



    // 发布时间
    $begin_date = @$_GET['begin_date'];
    $end_date   = @$_GET['end_date'];
    if($begin_date == '') {
        $begin_date   = 0;
    } else {
        $tmp    = explode('-', $begin_date);
        $begin_date = mktime(0 ,0, 0,$tmp[1] ,$tmp[2], $tmp[0]);
    }
    if($end_date == '') {
        $end_date   = $timestamp;
    } else {
        $tmp        = explode('-', $end_date);
        $end_date   = mktime(23 ,59, 59,$tmp[1] ,$tmp[2], $tmp[0]);
    }
    $where .= "AND (addtime >= '$begin_date' AND addtime <= '$end_date' ) ";







    // 分页处理开始
    $csql   = "SELECT COUNT(*) AS rs_count FROM $tbl_faq $where";
	
	
    $rs     = $conn->GetRow($csql);


    $record_total   = @(int)$rs['rs_count'];
    $page_total     = ceil($record_total/$page_size);

    $page   = @(int)$_GET['page'];
    if($page < 1) $page = 1;
    if($page > $page_total && $page_total > 0) $page = $page_total;
    $offset = ($page - 1) * $page_size;
    $limit  = "LIMIT $offset, $page_size";

    $view_var['record_total']   = $record_total;
    $view_var['page_total']     = $page_total;
    $view_var['page']           = $page;
    $view_var['page_size']      = $page_size;
    // 分页处理完毕


    // 列表处理开始
    $order_by   = trim(@$_GET['orderby']);
    $order_desc = @(int)$_GET['desc'];

    $str_order_by   = '';
    if($order_by != '') {
        $order_desc = ($order_desc!=1)?'ASC':'DESC';
        $str_order_by = "`{$order_by}` {$order_desc}, ";
    }

    
    $sql    = "SELECT * FROM $tbl_faq
            $where 
            ORDER BY  $str_order_by id DESC ";
    //echo $sql;
    $rs = $conn->PageExecute($sql,$page_size,$page);
    $view_var['record'] = $rs->GetRows();
    // 列表处理结束


    return $view_var;
}


function read($id = 0) {
    global $_TABLES, $timestamp;

    $view_var   = array();
    $tbl_faq    = "yu_sqjm";
    if($id > 0) {
        $conn   = & get_db_conn();
        $sql    = "SELECT * FROM $tbl_faq WHERE id = $id LIMIT 0,1 ";
        $view_var   = $conn->GetRow($sql);
    } else {
        $view_var   = array(
              'id'      => 0,
              'cid'     => 0,
              'subject' => '',
              'content' => '',
              'answer'  => '',
              'email2sender' => 0,
              'display'     => 0,
              'sender'      => '',
              'senderemail' => '',
              'sendtime'   => $timestamp,
              'replier'     => '',
              'replytime'  => $timestamp,
              'reply'       => 0,
            );
    }
    return $view_var;
}

function modify() {
    global $_TABLES, $timestamp;
    $tbl_faq        = "yu_sqjm";
    $conn   = & get_db_conn();
    $sql    = "SELECT COUNT(*) AS rs_count FROM $tbl_faq 
                        WHERE cmname = '{$result['cmname']}' 
                          AND id <> '{$result['id']}' ";
	$rs     = $conn->GetRow($sql);
    if($rs['rs_count'] > 0) {
            $GLOBALS['ERR']->AddError(_ERROR_BUSINESS, 
                "系统当前分类中已经存在问题主题为<FONT COLOR=\"red\">{$result['cmname']}</FONT>的问题，无法当前修改操作！", 
                __FILE__,
                __LINE__);
    }
}

function del() {
    global $_TABLES;
    $tbl_faq    = "yu_sqjm";

    $deltype    = trim(@$_POST['deltype']);
    if($deltype == 'all') {
        // 删除POST传递过来的 item_id 
        // 批量删除
        $str_in = array_join_comma($_POST['item_id']);
    } else {
        // get传递过来的删除 单条删除
        $item_id= @(int)$_GET['item_id'];
        $str_in = $item_id;
    }

    if($str_in != '') {
        $conn   = & get_db_conn();
        $sql    = "DELETE FROM $tbl_faq 
                    WHERE id IN ({$str_in}) ";
        if($conn->Execute($sql)) {
            js_success('删除指定问题成功！');
        }
    }
}
?>